<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<html>
<head>
<%@ include file="/common/meta.jsp" %>
<title>岗位管理</title>

<script type="text/javascript">
var _path = "${_ctx}/bap/position";

$(function () {
    $("#layout1").ligerLayout({ leftWidth: 120, allowLeftResize: false, allowLeftCollapse: true, space: 2, heightDiff: -1 });

    $("#tree1").ligerTree({
        <%--contextPath:"${_ctx}/",--%>
        url: '${_ctx}/bap/organization/tree?rnd=' + Math.random(),
        onSelect: onSelect,
        onCancelselect: onCancelselect,
        attribute: ['id'],
        checkbox: false
    });

    initLayout();
    $(window).resize(function () {
        initLayout();
    });

    $("#mainGrid").ligerGrid({
        columns: [
            { display: 'id', name: 'id', width:60,hide: true},
            { display: '序号', width: 40, render: function (rowData, rowindex, value, column, rowid, page, pagesize) { return (page - 1) * pagesize + rowindex + 1; }},
            { display:'岗位代码', name:'code', align: 'center', width:70, editor: { type: 'text' }},
            { display:'岗位名称', name:'name', align: 'center', width:100, editor: { type: 'text' }},
            { display:'组织结构ID', name:'orgId', width:60,hide: true},
            { display:'组织结构', name:'organization.name', align:'center', width:100, minWidth:60, textField: 'orgName'}
        ], url: _path + "/list/json?rnd=" + Math.random(), delayLoad: false, sortName:"ranking", sortOrder:"desc",
        pageSize: 30, pageSizeOptions: [20, 30, 50, 100], width: '100%', height: '100%', heightDiff: -1,
        onSelectRow:function(host){

        }
    });

    divMenu = $.ligerMenu({ top:100, left:100, width:90, items:[
        { text:'刷新', click:f_reloadTree,icon:'refresh' }
    ]
    });

    $("#orgDiv").bind("contextmenu", function (e) {
        divMenu.show({ top:e.pageY, left:e.pageX });
        return false;
    });

});


/*属性结构选择行*/
function onSelect(note) {
    var manager = $("#mainGrid").ligerGetGridManager();
    manager.set('parms', {search_orgId: note.data.id, rnd: Math.random()});
    manager.loadData();
}

function onCancelselect(note) {
    var manager = $("#mainGrid").ligerGetGridManager();//alert(JSON2.stringify(note.data));
    manager.set('parms', {rnd: Math.random()});
    manager.loadData();
}

function f_reloadTree() {
    var mnager = $("#tree1").ligerGetTreeManager();
    mnager.clear();
    mnager.loadData(null, '${_ctx}/bap/organization/tree?rnd=' + Math.random());
}
//查询
function f_doSearch() {
    var form = new liger.get("searchPanel");
    var data = form.getData();

    var manager = $("#mainGrid").ligerGetGridManager();
    manager.set('parms', data);
    manager.loadData();
}

/*
* 确定选择岗位，并组装数据
* */
function f_hostJson(){
    var manager = $("#mainGrid").ligerGetGridManager();
    var rows = manager.getCheckedRows();
    var hosts = [];
    if (rows && rows.length > 0) {
        $(rows).each(function () {
            var hostJson = {id:this.id,name:this.name,code:this.code,organization:this.organization.name}
            hosts.push(hostJson);
        });
    }
    return hosts;
}








function f_load() {
    var manager = $("#mainGrid").ligerGetGridManager();
    manager.loadData(true);
}

</script>
</head>

<body style="padding: 0;overflow:hidden;">
<form id="searchForm" onsubmit="return false">
    <div id="layout1" style="margin: -1px">
        <div position="left" title="组织机构" style="height: 96%;overflow:auto;">
            <div id="orgDiv" style="width: 250px; height: 100%; margin: -1px; float: left; border: 1px solid #ccc; overflow: auto;">
                <ul id="tree1"></ul>
            </div>
        </div>
        <div position="center">
            <div id="toolbar"></div>
            <div id="mainGrid"></div>
        </div>
    </div>
</form>
</body>
</html>